package com.hg.library.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * Created by admin on 2017/2/20.
 */

public class MarqueeTextView extends TextView {

    public MarqueeTextView(Context context) {
        super(context);
        makeMarquee();
    }

    public MarqueeTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        makeMarquee();
    }

    private void makeMarquee() {
        setSingleLine();
        setMarqueeRepeatLimit(Integer.MAX_VALUE);
        try {

            Field mMarqueeFadeMode = getClass().getSuperclass().getDeclaredField("mMarqueeFadeMode");
            mMarqueeFadeMode.setAccessible(true);
            mMarqueeFadeMode.set(this, 0);

            Method startMarquee = getClass().getSuperclass().getDeclaredMethod("startMarquee");
            startMarquee.setAccessible(true);
            startMarquee.invoke(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean isSelected() {
        return true;
    }

}
